package com.spicdt.edge.protocol.door.demo.callback.dto;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@Data
public class OpenApiResult {

    /**
     * 200：成功，其他：失败
     */
    private String code;

    /**
     * 结果描述
     */
    private String msg;
    private Object data;

    public OpenApiResult() {
    }

    /**
     * 初始化一个新创建的 AjaxResult 对象
     *
     * @param code 状态码
     * @param msg  返回内容
     */
    public OpenApiResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public OpenApiResult(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static OpenApiResult success() {
        return new OpenApiResult("200", "操作成功");
    }

    public static OpenApiResult success(String msg) {
        return new OpenApiResult("200", msg);
    }

    public static OpenApiResult success(String msg, Object data) {
        return new OpenApiResult("200", msg, data);
    }

    public static OpenApiResult error() {
        return new OpenApiResult("500", "参数不正确");
    }

    public static OpenApiResult error(String msg) {
        return new OpenApiResult("500", msg);
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("code", getCode())
                .append("msg", getMsg())
                .append("data", JSON.toJSON(getData()).toString())
                .toString();
    }
}
